<template>
    <div>
        <vxe-toolbar custom  ref="toolbarRef" >
            <template #buttons>
                <!--<el-button-->
                        <!--type="primary"-->
                        <!--icon="el-icon-plus"-->
                        <!--@click="handleAdd"-->
                        <!--v-if="this.editable"-->
                <!--&gt;-->
                    <!--选择订单项-->
                <!--</el-button>-->
                <el-button
                        type="primary"
                        icon="el-icon-plus"
                        @click="selectAsn"
                        v-if="this.editable"
                >
                    选择ASN
                </el-button>
                <el-button
                        type="danger"
                        icon="el-icon-delete"
                        @click="showDelAsn"
                        v-if="this.editable"
                >
                    删除ASN
                </el-button>
            </template>
            <template #tools>

                <el-tooltip content="清空筛选" placement="top">
                    <vxe-button  icon="vxe-icon-delete" class="tool-btn" @click="$refs.tableRef.clearFilter()" circle></vxe-button>
                </el-tooltip>

                <vxe-button  icon="vxe-icon-refresh" class="tool-btn" @click="refresh" circle style="margin-right: 12px;"></vxe-button>
            </template>
        </vxe-toolbar>
        <vxe-grid
                v-bind="gridOptions"
                id="tableRef"
                ref="tableRef"
                show-footer
                class="mytable-scrollbar"
                :data="list"
                :edit-rules="validRules"
                :tooltip-config="{ zIndex: 9999 }"
                :customConfig="customConfig"
                :menu-config="menuConfig"
                :footer-method="footerMethod"
                :edit-config="{
                trigger: 'click',
                mode: 'row',
                showUpdateStatus: true,
                showInsertStatus: true,
                beforeEditMethod:beforeEdit}"
                @edit-closed="editClosedEvent"
                @edit-actived="editActivedEvent"
                @menu-click="contextMenuClickEvent">

            <!--<template #num_edit="scope">-->
                <!--<vxe-input v-model="scope.row.num" type="integer"  max="99999999" :controls="false"-->
                           <!--@change="(value)=>calNum(value.value,scope)"-->
                           <!--@blur="(value)=>checkNum(scope.row.num, scope.row)"-->
                <!--&gt;</vxe-input>-->
            <!--</template>-->

            <template #btn_default="{ row }">
                <template v-if="!isActiveStatus(row) && this.editable">
                    <!--<el-tooltip content="修改" placement="top">-->
                    <!--<el-button-->
                    <!--size="small"-->
                    <!--type="primary"-->
                    <!--@click="handleUpdate(row)"-->
                    <!--&gt;修改-->
                    <!--</el-button>-->
                    <!--</el-tooltip>-->

                    <!--<el-tooltip content="删除" placement="top">-->
                        <!--<el-button-->
                                <!--icon="el-icon-delete"-->
                                <!--link-->
                                <!--size="small"-->
                                <!--type="primary"-->
                                <!--@click="handleDelete(row)"-->
                        <!--&gt;</el-button>-->
                    <!--</el-tooltip>-->
                </template>
                <template v-else>
                </template>
            </template>
        </vxe-grid>
        <!--<select-order-item ref="selectOrderItemRef" @setOrderItemList="setOrderItemList" :notificationType="notificationType"></select-order-item>-->
        <select-asn ref="selectAsn" @setAsnList="setAsn"></select-asn>
        <delete-asn ref="deleteAsn" @delAsnList="delAsn"></delete-asn>
    </div>
</template>

<script>
    import {findList as asnItemList} from "@/api/anwise/logistics/asn_item";
    import {findList} from "@/api/anwise/logistics/cn_item";
    import {overflowNum} from "@/api/anwise/logistics/cn_main";
    import {mapGetters} from "vuex";
    import {VXETable} from 'vxe-table'
    import {getDictionary} from "@/api/system/dict"
    import {select} from "@/api/base/region";
    import {Pattern} from "@/utils/validate.js";
    import selectAsn from './select_asn.vue';
    import deleteAsn from './delete_asn.vue';
    // import selectOrderItem from './select_order_item.vue';
    import {select as supplierSelect} from "@/api/anwise/supplier";
    import {markRaw} from "vue"


    export default {
        components: {
            selectAsn,
            deleteAsn
            // selectOrderItem,
        },
        data() {
            return {
                props: {
                    label: 'nodeName',
                    value: 'id',
                },
                cnNo:'',
                dateFormat: 'YYYY-MM-DD',
                pickerOptions: {},
                editRow:{},
                rowIndex:'',
                box: false,
                purchaseType:'正常',
                supplierId:'',
                isEdit:false,
                iconSearch:true,
                searchShow:false,
                provinceList:[],
                cityList:[],
                editable:true,
                list: [],
                asnList:[],
                notificationType:"CN",
                customConfig: {
                    storage: true,
                    checkMethod({column}) {
                        if (['facName'].includes(column.field)) {
                            return false
                        }
                        return true
                    },
                },
                menuConfig: {},
                form: {},
                query: {},
                loading: true,
                data: [],
                selectionList: [],
                page: {
                    pageSize: 10,
                    currentPage: 1,
                    total: 0
                },
                subVisible: false,
                direction: 'rtl',
                customerName: "CN项",
                customerTypeList: [],
                nameOptions: [{data: null}],
                validRules: {
                    quantity: [
                        {required: true, message: '数量必须填写'}
                    ],

                },
                gridOptions: {
                    height: '400px',
                    border: true,
                    showOverflow: true,
                    keepSource: true,
                    size: "medium",
                    rowConfig: {
                        // keyField: 'id',
                        isHover: true
                    },
                    columnConfig: {
                        resizable: true
                    },
                    // editRules: ,
                    columns: [
                        // {type: 'checkbox', width: 50, fixed:'left', visible: true},
                        // {type: 'seq', width: 50, fixed:'left', align: "center"},
                        {
                            title: "CN项",
                            field: "cnItem",
                            maxlength:1000,
                            minWidth: 150,
                            fixed:'left',
                        },
                        {
                            title: "ASN编号",
                            field: "asnNo",
                            minWidth: 150,
                        },
                        {
                            title: "ASN项",
                            field: "asnItem",
                            minWidth: 150,
                        },
                        {
                            title: "PI  No#",
                            field: "piNo",
                            maxlength:1000,
                            minWidth: 150,
                        },
                        // {
                        //     title: "备货公司",
                        //     field: "supplierNo",
                        //     minWidth: 150,
                        // },
                        {
                            title: "客户条码",
                            field: "customerCode",
                            minWidth: 150,
                        },
                        {
                            title: "物料名称",
                            field: "materialName",
                            minWidth: 150,
                            filters: [{ data: '' }],
                            filterRender: { name: 'FilterInput'}
                        },
                        {
                            title: "物料编号",
                            field: "materialNo",
                            minWidth: 150,
                            filters: [{ data: '' }],
                            filterRender: { name: 'FilterInput'}
                        },
                        {
                            title: "数量",
                            field: "num",
                            // editRender: {placeholder: '请输入...', autofocus: '.vxe-input--inner', autoselect: true},
                            // slots: {edit: 'num_edit'},
                            minWidth: 120,
                        },
                        {
                            title: "箱数",
                            field: "ctnNum",
                            minWidth: 120,
                        },
                        // {
                        //     title: "包装规格",
                        //     field: "packNum",
                        //     type:"html",
                        //     minWidth: 120,
                        //     // editRender: {placeholder: '请输入...', autofocus: '.vxe-input--inner', autoselect: true},
                        //     // slots: {edit: 'price_edit'}
                        // },
                        {
                            title: "送货工厂",
                            field: "facName",
                            minWidth: 120,
                        },
                        {
                            title: "送货地址",
                            field: "facAddr",
                            minWidth: 120,
                        },
                        {
                            title: "联系人",
                            field: "contact",
                            minWidth: 120,
                        },
                        {
                            title: "联系人电话",
                            field: "contactPhone",
                            minWidth: 120,
                        },
                        {
                            title: "毛重/箱",
                            field: "ctnPerGw",
                            minWidth: 120,
                        },
                        {
                            title: "净重/箱",
                            field: "ctnPerNw",
                            minWidth: 120,
                        },
                        {
                            title: "包装尺寸(cm)",
                            field: "size",
                            minWidth: 250,
                            align:'center',
                            children:[
                                {
                                    title: "长",
                                    field: "length",
                                    minWidth: 120,
                                },
                                {
                                    title: "宽",
                                    field: "width",
                                    minWidth: 120,
                                },
                                {
                                    title: "高",
                                    field: "height",
                                    minWidth: 120,
                                },
                            ],
                        },
                        {
                            title: "总CBM",
                            field: "totalCbm",
                            minWidth: 120,
                        },
                        // {
                        //     field: 'btn',
                        //     title: '操作',
                        //     minWidth: 120,
                        //     align: "center",
                        //     fixed: "right",
                        //     visible: true,
                        //     slots: {default: 'btn_default'}
                        // }
                    ]
                },
                supplierDic:[]
            };
        },
        computed: {
            ...mapGetters(["permission"]),
            permissionList() {
                return {
                    addBtn: this.validData(this.permission.purchase_main_add, false),
                    viewBtn: this.validData(this.permission.purchase_main_view, false),
                    delBtn: this.validData(this.permission.purchase_main_delete, false),
                    editBtn: this.validData(this.permission.purchase_main_edit, false)
                };
            },
            ids() {
                let ids = [];
                this.selectionList.forEach(ele => {
                    ids.push(ele.id);
                });
                return ids.join(",");
            },
            subIds() {
                let ids = [];
                this.selectionListSub.forEach(ele => {
                    ids.push(ele.id);
                });
                return ids.join(",");
            }
        },
        mounted() {
            this.isEdit = false;
            this.disabledCommit(false);
            this.init();
            this.$nextTick(() => {
                console.log(this.$refs.tableRef)
                console.log(this.$refs.toolbarRef)
                this.$refs.tableRef.connect(this.$refs.toolbarRef);
            })
        },
        methods: {
            init(){
                supplierSelect().then(res=>{
                    this.supplierDic = res.data.data;
                })
            },
            showDelAsn() {
                this.$refs.deleteAsn.showSelect(this.asnList);
            },
            async delAsn(list) {
                console.log("list",list);
                list.forEach(item => {
                    let rowIndex = this.asnList.findIndex(it => it.asnNo == item.asnNo);
                    if (rowIndex != -1) {
                        this.asnList.splice(rowIndex,1);
                    }
                })
                let delList = [];
                await this.$refs.tableRef.getTableData().fullData.forEach(row => {
                    if (list.some((val) => val.asnNo=== row.asnNo)) {
                        delList.push(row);
                    }
                })
                console.log("delList",delList);
                this.$refs.tableRef.remove(delList);
            },
            async setAsn(list) {
                list.forEach(item => {
                    this.asnList.push(item);
                    asnItemList({asnNo:item.asnNo}).then(res => {
                        console.log(res);
                        if (res.data.success) {
                            let list = res.data.data;
                            console.log(list);
                            const $table = this.$refs.tableRef
                            let asnData = markRaw(list);
                            if (list.length > 0) {
                                this.$emit("disabledFiled", true);
                            }
                            if (!$table.getEditRecord()) {
                                let $this = this;
                                let existsList = $this.$refs.tableRef.getTableData().fullData;
                                for (let i = 0; i<asnData.length; i++) {
                                    let item = asnData[i];
                                    if (!existsList.some((val) => val.asnNo === item.asnNo && val.asnItem === item.asnItem)) {

                                        let maxNo = 0;
                                        if ($this.$refs.tableRef.getTableData().fullData.length > 0) {
                                            maxNo = Number($this.$refs.tableRef.getTableData().fullData[$this.$refs.tableRef.getTableData().fullData.length - 1].cnItem);
                                        }
                                        let obj = {
                                            cnItem: maxNo + 1,
                                            asnNo: item.asnNo,
                                            asnItem: item.asnItem,
                                            piNo: item.piNo,
                                            piItem: item.orderItem,
                                            custPo: item.poNo,
                                            materialNo: item.productCode,
                                            materialName: item.productName,
                                            customerCode: item.customerCode,
                                            specification: item.specification,
                                            brand: item.brand,
                                            mcz: item.mcz,
                                            mateGroup: item.mateGroup,
                                            num: item.quantity,
                                            packNum: item.packNum,
                                            ctnPerGw: item.ctnGw,
                                            ctnPerNw: item.ctnNw,
                                            length:item.length,
                                            width: item.width,
                                            height:item.height,
                                            ctnNum : item.ctnNum,
                                            totalGw : item.totalGw,
                                            totalNw : item.totalNw,
                                            totalCbm : item.totalCbm,
                                            contact: item.contact,
                                            contactPhone: item.contactPhone,
                                            facAddr: item.facAddr,
                                            facName: item.facName
                                        };
                                        $this.$refs.tableRef.insertAt(obj, -1);
                                    }
                                }
                            }
                        }
                    })
                })
            },
            selectAsn() {
                this.$refs.selectAsn.showSelect(this.asnList);
            },
            async setOrderItemList(list) {
                console.log("setOrderItemList", list);
                const $table = this.$refs.tableRef
                let selectData = markRaw(list);
                if (list.length > 0) {
                    this.$emit("disabledFiled", true);
                }
                const existsList = this.$refs.tableRef.getTableData().fullData;
                let $ref = this.$refs;
                let $this = this;
                if (!$table.getEditRecord()) {
                    console.log(selectData)
                    for (let i = 0; i<selectData.length; i++) {
                        let item = selectData[i];
                        if (!existsList.some((val) => val.piNo === item.idNo && val.piItem === item.itemNo)) {
                            let length = 0, width = 0, height = 0;
                            if (item.packContent) {
                                let array = item.packContent.split('X');
                                length = array[0] || 0;
                                width = array[1] || 0;
                                height = array[2] || 0;
                            }
                            console.log("$ref", $ref);
                            let maxNo = 0;
                            if ($this.$refs.tableRef.getTableData().fullData.length > 0) {
                                maxNo = Number($this.$refs.tableRef.getTableData().fullData[$this.$refs.tableRef.getTableData().fullData.length - 1].cnItem);
                            }
                            let obj = {
                                cnItem: maxNo + 1,
                                piNo: item.idNo,
                                piItem: item.itemNo,
                                custPo: item.custPo,
                                materialNo: item.materialNo,
                                materialName: item.materialName,
                                customerCode: item.barCode,
                                specification: item.specification,
                                facAddr: item.facAddr,
                                facName: item.facName,
                                contact: item.contact,
                                contactPhone: item.contactPhone,
                                supplierNo: item.supplierNo,
                                supplierName: item.supplierName,
                                num: item.num - item.deliNum,
                                packNum: item.maxNum,
                                ctnPerGw: item.cost,
                                ctnPerNw: item.salesNum,
                                length: this.$toFixed(length * 100,2),
                                width: this.$toFixed(width * 100,2),
                                height: this.$toFixed(height * 100,2),
                            };
                            // new Promise((resolve, reject) =>{
                            await overflowNum(obj).then(res => {
                                obj.num = res.data.data;
                                console.log(obj.packNum)
                                if (obj.packNum >0) {
                                    obj.ctnNum = Math.ceil(obj.num / obj.packNum);//箱数
                                } else {
                                    obj.ctnNum = 0;
                                }
                                // obj.packNum = item.maxNum+"*"+obj.ctnNum;//包装规格
                                // let rem = obj.num % item.maxNum;
                                // if(rem){
                                //     obj.packNum = obj.packNum + "<br>" + rem+"*1"
                                // }
                                obj.totalCbm = this.$toFixed(obj.num * (obj.length * obj.width * obj.height / 1000000),2);
                                $this.$refs.tableRef.insertAt(obj, -1);
                                //         resolve(obj);
                                //     })
                            })
                            // .then((obj)=>{
                            //     console.log(obj)

                            // });

                            // $this.$refs.tableRef.insertAt(obj, -1);
                        }
                    }
                }
            },
            changePurchaseType(value) {
                this.purchaseType = value;
            },
            setData(editable,cnNo) {
                if(cnNo){
                    this.query.cnNo = cnNo
                    this.cnNo = cnNo
                }
                console.log("aaaaaa", this.idNo)
                // this.customerId = customerId
                this.onLoad(this.page)

                this.editable = editable;
                console.log(this.editable);
            },
            updateStatus(scope){
                this.$refs.tableRef.updateStatus(scope);
            },
            calcSum(list, field) {
                let count = 0
                list.forEach(item => {
                    count += Number(item[field])
                })
                if (field == 'num' || field == 'ctnNum') {
                    return count.toFixed(0);
                } else {
                    return this.$toFixed(count,2);
                }
            },
            // 在值发生改变时更新表尾合计
            updateFooterEvent (params) {
                let xTable = this.$refs.tableRef
                xTable.updateFooter()
            },
            footerMethod(table) {
                return [
                    table.columns.map((column, columnIndex) => {
                        if (columnIndex === 0) {
                            return '合计'
                        }
                        if ([ 'num','ctnNum','totalCbm'].includes(column.field)) {
                            return this.calcSum(table.data, column.field)
                        }
                        return null
                    })
                ]
            },
            calNum(num,scope) {
                console.log("num",num);
                this.$refs.tableRef.updateStatus(scope);
                let row=scope.row;
                if (num) {
                    if(row.maxNum!=="0"){
                        row.ctnNum = Math.ceil(row.num / row.maxNum);//箱数
                    }else{
                        row.ctnNum = 0;
                    }
                    // obj.packNum = item.maxNum+"*"+obj.ctnNum;//包装规格
                    // let rem = obj.num % item.maxNum;
                    // if(rem){
                    //     obj.packNum = obj.packNum + "<br>" + rem+"*1"
                    // }
                    row.totalCbm = this.$toFixed(row.num * (row.length * row.width * row.height / 1000000),2);
                }
            },
            checkNum(num, row) {
                overflowNum(row).then(res => {
                    if (num > res.data.data) {
                        row.num = res.data.data;
                        if(row.maxNum>0){
                            row.ctnNum = Math.ceil(row.num / row.maxNum);//箱数
                        }else{
                            row.ctnNum = 0;
                        }
                        // obj.packNum = item.maxNum+"*"+obj.ctnNum;//包装规格
                        // let rem = obj.num % item.maxNum;
                        // if(rem){
                        //     obj.packNum = obj.packNum + "<br>" + rem+"*1"
                        // }
                        row.totalCbm = this.$toFixed(row.num * (row.length * row.width * row.height / 1000000),2);
                        this.updateFooterEvent();
                        this.$message({
                            type: "warning",
                            message: "数量不能大于["+row.num+"]!"
                        });
                    }
                })
            },
            refresh(){
                this.page = {
                    pageSize: 10,
                    currentPage: 1,
                }
                this.query = {}
                this.onLoad(this.page)
            },
            pageChange(e){
                this.page = {
                    pageSize: e.pageSize,
                    currentPage: e.currentPage,
                }
                this.onLoad(this.page)
            },

            isActiveStatus(row) {
                const $table = this.$refs.tableRef
                if ($table) {
                    return $table.isEditByRow(row)
                }
            },
            clearAll() {
                this.data = [];
                this.$refs.tableRef.remove();
            },
            handleAdd() {
                this.$refs.selectOrderItemRef.showSelect(this.$refs.tableRef.getTableData().fullData);
                // this.isEdit = true;
                // const $table = this.$refs.tableRef
                // if (!$table.getEditRecord()) {
                //     console.log(this.tableRef)
                //     if ($table) {
                //         const obj = $table.insertAt({}, -1).then(res => {
                //             $table.setEditCell(res.row, 'facName');
                //         })
                //         console.log(obj)
                //         // this.searchShow = false
                //         // this.iconSearch = false
                //     }
                // }
            },
            contextMenuClickEvent(data) {
                const menu = data.menu;
                const row = data.row;
                const column = data.column;
                const $table = this.$refs.tableRef
                if ($table) {
                    switch (menu.code) {
                        case 'hideColumn':
                            $table.hideColumn(column)
                            break
                        case 'showAllColumn':
                            $table.resetColumn(true)
                            break
                        case 'copy':
                            // if (XEClipboard.copy(row[column.field])) {
                            //   ElMessage.success('保存成功')
                            // }
                            // ElMessage.success('复制成功')
                            break
                        case 'reload':
                            //  findList()
                            break
                        case 'insertAt':
                            $table.insertAt({}, row || -1).then(({row}) => {
                                $table.setEditCell(row, column || 'name')
                            })
                            break
                        case 'remove':
                            $table.remove(row)
                            break
                        case 'save':
                            // ElMessage.success('保存成功')
                            break
                    }
                }
            },
            disabledCommit(data) {
                this.$emit("disabledCommit",data);
            },
            editActivedEvent(row){//激活单元格事件
                this.isEdit = true;
                this.disabledCommit(true);
            },
            editClosedEvent(row) {
                console.log(row)
                const $table = this.$refs.tableRef;
                $table.clearValidate();
                this.disabledCommit(false);
                // const $table = this.$refs.tableRef
                // console.log($table.getTableData().fullData);
                // const err = this.validEvent(row.row);
                // if (err) {
                //     return
                // }
                // if (row.column.field=='prodNum') {
                //     this.overflowNum(row.row.prodNum, row.row);
                // }

            },
            async handleSaveRow(row) {
                const err = await this.validEvent(row);
                if (err) {
                    return
                }

            },
            async validEvent(row) {
                const $table = this.$refs.tableRef
                const errMap = await $table.validate(row).catch(errMap => errMap)
                return errMap;

            },
            formatType(value) {
                let value2 = "";
                this.customerTypeList.forEach(res => {
                    if (value === res.dictKey) {
                        value2 = res.dictValue;
                    }
                });
                return value2
            },

            // 主表模块
            rowSave(row, done, loading) {
                add(row).then(() => {
                    this.onLoad(this.page);
                    this.$message({
                        type: "success",
                        message: "操作成功!"
                    });
                    done();
                }, error => {
                    window.console.log(error);
                    loading();
                });
            },
            rowUpdate(row, index, done, loading) {
                update(row).then(() => {
                    this.onLoad(this.page);
                    this.$message({
                        type: "success",
                        message: "操作成功!"
                    });
                    done();
                }, error => {
                    window.console.log(error);
                    loading();
                });
            },
            rowDel(row) {
                this.$confirm("确定将选择数据删除?", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                    .then(() => {
                        return remove(row.id);
                    })
                    .then(() => {
                        this.onLoad(this.page);
                        this.$message({
                            type: "success",
                            message: "操作成功!"
                        });
                    });
            },
            async handleDelete(row) {
                console.log("row",this.list);
                const $table = this.$refs.tableRef
                if (row.id) {
                    this.$confirm('是否确认删除?', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                    }).then(() => {
                        if ($table.getTableData().fullData.length === 1) {
                            this.$emit("disabledFiled", false);
                        }
                        $table.remove(row)
                    }).then(() => {
                        this.$message({type: "success", message: "操作成功，保存后生效!"});
                    })
                } else {
                    console.log("$table.getTableData().fullData.length",$table.getTableData().fullData.length);
                    if ($table.getTableData().fullData.length === 1) {
                        this.$emit("disabledFiled", false);
                    }
                    $table.remove(row)

                }
            },
            // handleDelete() {
            //   if (this.selectionList.length === 0) {
            //     this.$message.warning("请选择至少一条数据");
            //     return;
            //   }
            //   this.$confirm("确定将选择数据删除?", {
            //     confirmButtonText: "确定",
            //     cancelButtonText: "取消",
            //     type: "warning"
            //   })
            //     .then(() => {
            //       return remove(this.ids);
            //     })
            //     .then(() => {
            //       this.onLoad(this.page);
            //       this.$message({
            //         type: "success",
            //         message: "操作成功!"
            //       });
            //       this.$refs.crud.toggleSelection();
            //     });
            // },
            beforeEdit({ row, rowIndex, column, columnIndex }) {
                if (this.editable) {

                }
                return this.editable;
            },
            beforeOpen(done, type) {
                if (["edit", "view"].includes(type)) {
                    getDetail(this.form.id).then(res => {
                        this.form = res.data.data;
                    });
                }
                done();
            },
            searchReset() {
                this.query = {};
                this.onLoad(this.page);
            },
            searchChange(params, done) {
                this.query = params;
                this.page.currentPage = 1
                this.onLoad(this.page, params);
                done();
            },
            selectionChange(list) {
                this.selectionList = list;
            },
            selectionClear() {
                this.selectionList = [];
                if(this.$refs.crud)  this.$refs.crud.toggleSelection();
            },
            currentChange(currentPage) {
                this.page.currentPage = currentPage;
            },
            sizeChange(pageSize) {
                this.page.pageSize = pageSize;
            },
            formateDate(list) {
                list.forEach(item => {
                    item.maxQuantity = item.orderNum;
                })
            },
            onLoad(page, params = {}) {
                this.query.cnNo = this.cnNo;
                if (this.$refs.tableRef.getInsertRecords().length>0 || this.$refs.tableRef.getRemoveRecords().length>0 ||
                    this.$refs.tableRef.getUpdateRecords().length>0) {
                    this.$confirm("搜索会丢失本次新增/编辑/删除的数据，确定继续吗?", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning"
                    })
                        .then(() => {
                            this.loading = true;
                            console.log('aaaaaaaaaaaa', this.query)
                            findList(Object.assign(params, this.query)).then(res => {
                                const data = res.data.data;
                                // data.forEach(res=>{
                                //     res.packNum = res.maxNum+"*"+res.ctnNum;//包装规格
                                //     let rem = res.num % res.maxNum;
                                //     if(rem){
                                //         res.packNum = res.packNum + "<br>" + rem +"*1"
                                //     }
                                // })
                                // this.page.total = data.total;
                                this.list = data;
                                this.loading = false;
                                this.selectionClear();
                                this.isEdit = false;
                                this.formateDate(this.list);
                            });
                        })
                }else {
                    this.loading = true;
                    console.log('aaaaaaaaaaaa', this.query)
                    findList(Object.assign(params, this.query)).then(res => {
                        const data = res.data.data;
                        // data.forEach(res=>{
                        //     res.packNum = res.maxNum+"*"+res.ctnNum;//包装规格
                        //     let rem = res.num % res.maxNum;
                        //     if(rem){
                        //         res.packNum = res.packNum + "<br>" + rem +"*1"
                        //     }
                        // })
                        // this.page.total = data.total;
                        this.list = data;
                        this.loading = false;
                        this.selectionClear();
                        this.isEdit = false;
                        this.formateDate(this.list);
                    });
                }
            },

        }
    };
</script>

<style scoped>
    :deep(.vxe-pulldown.size--medium){
        z-index: 99999 !important;
    }
    .vxe-table--tooltip-wrapper {
        z-index: 10000 !important;
    }
    :deep(.vxe-table--fixed-right-wrapper){
        z-index: 99999 !important;
    }
    :deep(.vxe-table--render-default.size--medium .vxe-header--column:not(.col--ellipsis)) {
        padding: 1px 0 !important;
    }
</style>
